﻿using MDIDemo.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DevMy.Vou
{
    public partial class Form_stongParaBase : Form_BaseDialog
    {
        public Form_stongParaBase()
        {
            InitializeComponent();
        }
        public StrongParaModel strongParaModel;
        public void Ini()
        {
            base.SetComponent();
        }
        /// <summary>
        /// 窗体状态
        /// </summary>
        /// <param name="WinType">-1：查看，0：修改，1：增加</param>
        public void SetWinType(int WinType)
        {
            base.WinType = WinType;
        }
        protected override void DisplayComponent(string id)
        {
            if (id != null)
            {
                string Sql = string.Format("Select * From strongPara Where id ='{0}'", id);
                DataTable dataTable = base.class_MySqlDataBase.GetDataTable(Sql);
                if (dataTable != null && dataTable.Rows.Count == 1)
                {
                    DataRow dataRow = dataTable.Rows[0];
                    if (dataRow != null)
                    {
                        this.textEdit1.Text = dataRow["englishAll"].ToString();
                        this.textEdit2.Text = dataRow["englishName"].ToString();
                        this.textEdit3.Text = dataRow["chinaName"].ToString();
                        this.textEdit4.Text = dataRow["paraType"].ToString();
                        this.spinEdit3.Value = decimal.Parse(dataRow["smallPoint"].ToString());
                        this.textEdit5.Text = dataRow["site"].ToString();
                        this.spinEdit1.Value = decimal.Parse(dataRow["sortNo"].ToString());
                        this.textEdit6.Text = dataRow["strongName"].ToString();
                        switch (dataRow["strongClass"].ToString())
                        {
                            case "I":
                                this.comboBoxEdit1.SelectedIndex = 0;
                                break;
                            case "II":
                                this.comboBoxEdit1.SelectedIndex = 1;
                                break;
                            case "III":
                                this.comboBoxEdit1.SelectedIndex = 2;
                                break;
                            case "IV":
                                this.comboBoxEdit1.SelectedIndex = 3;
                                break;
                            case "V":
                                this.comboBoxEdit1.SelectedIndex = 4;
                                break;
                            default:
                                this.comboBoxEdit1.SelectedIndex = 0;
                                break;
                        }
                    }
                }
            }
        }
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            if (this.textEdit1.Text == "" || this.textEdit1.Text.Length == 0)
            {
                MessageBox.Show("英文全称不能为空！", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.textEdit2.Text == "" || this.textEdit2.Text.Length == 0)
            {
                MessageBox.Show("英文简称不能为空！", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.textEdit3.Text == "" || this.textEdit3.Text.Length == 0)
            {
                MessageBox.Show("中文全称不能为空！", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.textEdit4.Text == "" || this.textEdit4.Text.Length == 0)
            {
                MessageBox.Show("参数类型不能为空！", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.textEdit6.Text == "" || this.textEdit6.Text.Length == 0)
            {
                MessageBox.Show("岩体名称不能为空！", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            strongParaModel = new StrongParaModel();
            if (base.WinType == 1)
                strongParaModel.id = DateTime.Now.ToString("yyyyMMddHHmmss");
            else
                strongParaModel.id = id;
            strongParaModel.englishAll = this.textEdit1.Text.Trim();
            strongParaModel.englishName = this.textEdit2.Text.Trim();
            strongParaModel.chinaName = this.textEdit3.Text.Trim();
            strongParaModel.paraType = this.textEdit4.Text.Trim();
            strongParaModel.smallPoint = int.Parse(this.spinEdit3.Value.ToString());
            strongParaModel.site = this.textEdit5.Text.Trim();
            strongParaModel.sortNo = int.Parse(this.spinEdit1.Value.ToString());
            strongParaModel.strongName = this.textEdit6.Text.Trim();
            strongParaModel.strongClass = this.comboBoxEdit1.Text;

            this.DialogResult = DialogResult.OK;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
